<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ include file="../common/base.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>

<meta http-equiv="X-UA-Compatible" content="IE=10" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>login</title>
<link href="${path }/dist/css/bootstrap.min.css" rel="stylesheet" />
<link href="${path }/dist/css/Buttom.css" rel="stylesheet" />
<link href="${path }/dist/css/flat-ui.css" rel="stylesheet">
<link href='${path }/dist/css/zTreeStyle/zTreeStyle.css'
	rel='stylesheet' />
<link
	href="http://cdn.bootcss.com/font-awesome/4.2.0/css/font-awesome.min.css"
	rel="stylesheet">
<style type="text/css">
.ztree>li {
	float: left;
	display: inline;
	width: 185px;
	height: 600px;
	padding-bottom: 20px;
}
.ztree>li:nth-child(even){
	background-color: #f9f9f9;
}
.ztree span.button.switch{
	display: none;/* 取消树的+/-*/
}
</style>
</head>
<body>
	<div class="panel panel-default">
		<div class="panel-heading" style="background: none;">
			<span class="fui-windows-8"></span> <span>编&nbsp;辑&nbsp;角色&nbsp;权&nbsp;限 &nbsp;-&nbsp;超级管理员</span>
			<button type="button" class="buttons button-caution button-rounded button-tiny"  style="float: right; margin-right: 60px;" onclick="javascript :history.back(-1)">取消</button>
			<button type="button"
				class="buttons button-royal button-rounded button-tiny"
				style="float: right; margin-right: 5px;" onclick="checkedcount()">完成</button>

		
		</div>
		<div class="panel-body" style="padding: 0px;">
			<div id='purviewTreeNode' class="ztree"></div>
			<form action="${path }/role/editrole" method="post" id="roleEdit">
				<input type="hidden" id="roleid" name="roleid" value="<%=request.getParameter("roleid")%>">
				<input type="hidden" id="purviewid" name="purviewid" value="">
				
			</form>
		</div>
	</div>

	<script src='${path }/dist/js/jquery.min.js'></script>
	<script src='${path }/dist/js/bootstrap.min.js'></script>
	<script src='${path }/dist/js/jquery.ztree.core-3.5.js'></script>
	<script src='${path }/dist/js/jquery.ztree.excheck-3.5.js'></script>
	<script src='${path }/dist/js/jquery.ztree.exedit-3.5.js'></script>
	<script type="text/javascript">
	<!--

		var settingPurview = {
			view : {
				selectedMulti : false,//多选
				showLine : false,//不显示链接线
				txtSelectedEnable : false,//不可以选择文字
				showIcon : false,//不显示ico
				dblClickExpand: false//不允许双击展开关闭节点

			},
			async : {
				enable : true,
				url : "${path}/emp/loadpurviewTree",
				autoParam : [ "id" ],
				otherParam : {
					"otherParam" : "zTreeAsyncTest","roleid":$("#roleid").val()
				},//提交的参数[key：value]
				dataFilter : filter
			},
			callback : {
				beforeClick : beforeClick,
				beforeAsync : beforeAsync,
				onAsyncError : onAsyncError,
				onAsyncSuccess : onAsyncSuccess
			},
			data : {
				simpleData : {
					enable : true,
				}
			},
			check : {
				enable : true,
				chkStyle : "checkbox",
				nocheckInherit: false,
				chkboxType : {
					"Y" : "ps",
					"N" : "ps"
				}
			}
		};
		function filter(treeId, parentNode, childNodes) {
			if (!childNodes)
				return null;
			for (var i = 0, l = childNodes.length; i < l; i++) {
				childNodes[i].name = childNodes[i].name.replace(/\.n/g, '.');
			}
			return childNodes;
		}
		function beforeClick(treeId, treeNode) {
			return true;
		}
		function beforeAsync(treeId, treeNode) {
		//异步加载之前调用
			return true;
		}
		function onAsyncError(event, treeId, treeNode, XMLHttpRequest,
				textStatus, errorThrown) {
			//showLog("[ "+getTime()+" onAsyncError ]&nbsp;&nbsp;&nbsp;&nbsp;" + ((!!treeNode && !!treeNode.name) ? treeNode.name : "root") );
		}
		function onAsyncSuccess(event, treeId, treeNode, msg) {
			var treeObj = $.fn.zTree.getZTreeObj(treeId);
			var nodes = treeObj.transformToArray(treeObj.getNodes());
			//alert(nodes.length);
			for(var i=0;i<nodes.length;i++){
				if(nodes[i].isParent){
					nodes[i].nocheck=true;
					treeObj.updateNode(nodes[i]);
				}
			}
			//showLog("[ "+getTime()+" onAsyncSuccess ]&nbsp;&nbsp;&nbsp;&nbsp;" + ((!!treeNode && !!treeNode.name) ? treeNode.name : "root") );
			
		}
		//完成
		function checkedcount(){
			var treeObj = $.fn.zTree.getZTreeObj("purviewTreeNode");
			var nodes = treeObj.getCheckedNodes(true);
			var purviewid ="";
			for(var i=0;i<nodes.length;i++){
				//alert(nodes[i].id);
				purviewid+=nodes[i].id+"";
				if(i<nodes.length-1)	purviewid+=",";
			}
			$('#purviewid').val(purviewid);
			$('#roleEdit').submit();
			//alert(purviewid);
		}
		$(document).ready(function() {
			//alert("${path}");
			$.fn.zTree.init($("#purviewTreeNode"), settingPurview);
		});
	//-->
	</script>
</body>
</html>